package com.xj.customer.controller;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.xj.customer.feign.ProductFeignService;
import com.xj.customer.feign.ServiceFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/customer")
public class CustomerController {
//    @Autowired
//    private RestTemplate restTemplate;
    @Autowired
    private ProductFeignService productFeignService;
    @Autowired
    private ServiceFeignService serviceFeignService;

    @GetMapping("/get")
    public String getService(){
        //String forObject = restTemplate.getForObject("http://product/product/get/2", String.class);
        String msg = serviceFeignService.get();
        String pro = productFeignService.get("3");
        return "调用成功:"+msg+"#"+pro;
    }
    @SentinelResource(value = "show", blockHandler = "myBlockHandler")
    @GetMapping("/show")
    public String show(){
        return "调用show接口";
    }

    public String myBlockHandler(BlockException blockException){
        return "###进入控流###";
    }

    @GetMapping("/sleep")
    public String sleep() throws InterruptedException {
        Thread.sleep(2000);
        return "调用sleep成功";
    }
}
